package 多线程;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author : K k
 * @date : 20:18 2020/8/26
 * 多线程小案例
 */
public class RunnableTest2 implements Runnable {
    private int threadCnt = 10;

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                if (threadCnt > 0) {
                    System.out.println(Thread.currentThread().getName() + " 剩余个数 " + threadCnt);
                    threadCnt--;
                    try {
                        Thread.sleep(30);
                        
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    break;
                }

            }
        }
    }

    public static void main(String[] args) {
        RunnableTest2 runnableTest2 = new RunnableTest2();
        new Thread(runnableTest2).start();
        new Thread(runnableTest2).start();

    }
}